﻿using System;
using System.Globalization;
using System.Threading;

namespace DateFormat
{
    class DateFormat
    {
        static void Main(string[] args)
        {
            DateTime dt;
            string[] allowedFormats = { "dd.MM.yyyy", "dd/MM/yyyy", "dd.MM.yy", "dd/MM/yy" };
            string[] dates = { "15.08.2001", "15/08/2002", "15.08.03", "15/08/04" };
            foreach (var date in dates)
            {
                foreach (var format in allowedFormats)
                {
                    try
                    {
                        dt = DateTime.ParseExact(date, format, CultureInfo.InvariantCulture.DateTimeFormat);
                        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
                        Console.WriteLine("day={0}, month={1}, year={2}", dt.Day, dt.Month, dt.Year);
                    }
                    catch (FormatException)
                    {
                    }
                }
            }
        }
    }
}